package com.xwb.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xwb.domain.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MessageDao extends BaseMapper<Message> {
    /**
     * 实现邀请队员的方法之一：
     * 将邀请的队员信息和发送者（队长信息）保存到到message表里
     */
    @Insert("insert into message (receiver_id, receving_time, " +
            "message_type, message_context, receiver_decision, message_sender, " +
            "sender_teamNumber, sender_teamName, competition_id)" +
            "VALUES (#{receiverId},#{receivingTime},#{messageType},#{messageContext}," +
            "#{receiverDecision},#{messageSender},#{senderTeamNumber},#{senderTeamName},#{competitionId})")
    void saveInvitation(Message message);

    /**
     * 将邀请的信息发送给邀请的队员
     */
    @Select("select message_context from message where receiver_id = #{receiverId}")
    String sendMessageToReceiver(String receiverId);

    /**
     * 接收邀请成员的决定信息并保存到message表里
     */
    @Update("update message set receiver_decision = #{receiberDecision} where receiver_id = #{receiverId} ")
    String receiveDecision(String receiverId,String receiverDecision);


}
